package com.wkhyapp.lm.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wkhyapp.lm.R;
import com.wkhyapp.lm.http.vo.CCategory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fang on 2022/1/19.
 */

public class CategoryItemAdapter extends BaseAdapter {


    private List<CCategory> list = new ArrayList<>();
    private LayoutInflater mInflater;


    public CategoryItemAdapter(Context context, List<CCategory> list) {
        this.mInflater = LayoutInflater.from(context);
        this.list = list;
    }
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return list.get(arg0);
    }
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_ccategory, null);
            holder.titleText = (TextView) convertView.findViewById(R.id.item_tv);
            holder.textrl = (RelativeLayout) convertView.findViewById(R.id.text_rl);
            holder.textiv = (ImageView) convertView.findViewById(R.id.text_iv);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.titleText.setText(list.get(position).getName());

        if (position == selectItem) {
            holder.textrl.setBackgroundColor(Color.parseColor("#FFFFFF"));
            holder.textiv.setVisibility(View.VISIBLE);
        }
        else {
            holder.textrl.setBackgroundColor(Color.parseColor("#F5F6F8"));
            holder.textiv.setVisibility(View.GONE);
        }
        return convertView;
    }
    public  void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
    }
    private int  selectItem=-1;

    public final class ViewHolder {
        public TextView titleText;
        public RelativeLayout textrl;
        public ImageView textiv;
    }
}